﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.JShop.UI;
using System.Data;

using CNVP.Framework.Utils;

namespace CNVP.JShop.Web.Admin.CommonWindows
{
    public partial class AjaxReview : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string action = Request.QueryString["action"].Trim();
            int count = 0;
            var reviewIDs=Request.Form["idset"];
            BLL.CNVP_Review review = new BLL.CNVP_Review();
            if (!String.IsNullOrEmpty(reviewIDs))
            {
                switch (action)
                {
                    case "Delete":
                        count = review.DeleteReviewBySet(Public.FilterSqlString(reviewIDs));
                        if (count > 0)
                        {
                            Response.Write("{error:\"0\"}");
                        }
                        else
                        {
                            Response.Write("{error:\"1\"}");
                        }
                        Response.End();
                        break;
                    case "Stat":
                        Dictionary<int,string> statType=new Dictionary<int,string>();
                        statType.Add(1, "IsTop");
                        statType.Add(2, "IsShow");
                        statType.Add(3, "IsDelete");
                        var field = Request.QueryString["FieldID"];
                        if (String.IsNullOrEmpty(field) || !Public.IsNumber(field) || (field != "1" && field != "2" && field != "3"))
                        {
                            Response.Write("{error:\"1\"}");
                            Response.End();
                        }
                        if (String.IsNullOrEmpty(Request.QueryString["value"]) || Request.QueryString["value"] == "false")
                        {
                            count = review.ChangeReviewStatFalseBySet(statType[Convert.ToInt32(field)], Public.FilterSqlString(reviewIDs));
                        }
                        else
                        {
                            count = review.ChangeReviewStatTrueBySet(statType[Convert.ToInt32(field)], Public.FilterSqlString(reviewIDs));
                        }
                        
                        if (count > 0)
                        {
                            Response.Write("{error:\"0\"}");
                        }
                        else
                        {
                            Response.Write("{error:\"1\"}");
                        }
                        Response.End();
                        break;
                    default:
                        Response.Write("{error:\"1\"}");
                        Response.End();
                        break;

                }
            }
            else
            {
                if (action == "cleanup")
                {
                    count = review.CleanUpDeletedReview();
                    if (count > 0)
                    {
                        Response.Write("{error:\"0\"}");
                    }
                    else
                    {
                        Response.Write("{error:\"1\"}");
                    }
                    Response.End();
                }
                else
                {
                    Response.Write("{error:\"1\"}");
                    Response.End();
                }
            }
        }
    }
}